# Maintainer: gym603 <gui_yuan_miao@163.com>

_realname=protobuf
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=6.30.2
pkgrel=1
pkgdesc="Protocol Buffers (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: '
  'aur: '
  'purl: pkg:pypi/protobuf'
  "cpe: cpe:/a:google:protobuf-python"
)
url="https://github.com/protocolbuffers/protobuf"
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-protobuf=${pkgver#*.}")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "001-no-python-static-lib.patch")
sha256sums=('35c859ae076d8c56054c25b59e5e59638d86545ed6e2b6efac6be0b6ea3ba048'
            'e864e7964ad7693e6ce8dc3b91c779184457ce82fc075d2099bfcbc18e6808a3')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-no-python-static-lib.patch

  rm -rf "${srcdir}"/python-build-${MSYSTEM} | true
  cp -r "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/"python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  CFLAGS+=" -Wno-int-conversion" \
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
}
